﻿using ImoviesBlazorAntPro.Server.Data;
using ImoviesBlazorAntPro.Shared.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ImoviesBlazorAntPro.Server.Repository
{
    public class TeleplayVlinkRepository : ITeleplayVlinkRepository
    {
        private readonly ApplicationDbContext _dbContext;

        public TeleplayVlinkRepository(ApplicationDbContext dbContext)
        {
            this._dbContext = dbContext;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="teleplayVlink"></param>
        public void AddTeleplayVlink(TeleplayVlink teleplayVlink)
        {
            _dbContext.Set<TeleplayVlink>().Add(teleplayVlink);
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="teleplayVlinks"></param>
        /// <returns></returns>
        public async Task BatchAddTeleplayVlink(IEnumerable<TeleplayVlink> teleplayVlinks)
        {
            await _dbContext.Set<TeleplayVlink>().AddRangeAsync(teleplayVlinks);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="teleplayVlinkId"></param>
        /// <exception cref="NotImplementedException"></exception>
        public async Task DeleteTeleplayVlink(uint teleplayVlinkId)
        {
            var t = await _dbContext.Set<TeleplayVlink>().FindAsync(teleplayVlinkId);
            if (t != null)
            {
                _dbContext.Set<TeleplayVlink>().Remove(t);
            }
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public void DeleteBatch(List<uint> Ids)
        {
            var list = _dbContext.Set<TeleplayVlink>().Where(x => Ids.Contains(x.Id)).ToList();
            if (list.Count > 0)
            {
                _dbContext.Set<TeleplayVlink>().RemoveRange(list);
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="teleplayVlink"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void UpdateTeleplayVlink(TeleplayVlink teleplayVlink)
        {
            _dbContext.Set<TeleplayVlink>().Update(teleplayVlink);
        }


        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        public Task<bool> SaveAsync()
        {
            return Task.FromResult(_dbContext.SaveChanges() > 0);
        }
    }
}
